home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ASME's Mechanical Engine…ing Toolkit 1997 December
/
ASME's Mechanical Engineering Toolkit 1997 December.iso
/
c_lang
/
varinc.lzh
/
REIN.C
< prev
next >
Wrap
Text File
|
1979-11-30
|
2KB
|
37 lines
/*****************************************************************************/
/* REIN reindents C programs, converting from one number of spaces per */
/* indent to another. REIN is a filter. The following call converts from 5 */
/* spaces per indent to 3: */
/* REIN 5 3 <OLDPGM.C >NEWPGM.C */
/*****************************************************************************/
#include <stdio.h>
main(ac, av) /* main() is passed two parameters. */
unsigned ac; /* command line argument count; 1 if no arguments */
char *av[]; /* array of pointers to strings from command line */
{
char buf[BUFSIZ];
short old_indent, new_indent, indent, new_spc;
if (ac != 3)
err_exit("Usage: reindent #_old_indent #_new_indent\n", "");
old_indent = atoi(av[1]); /* Convert command-line numbers */
new_indent = atoi(av[2]); /* from string to binary. */
if (old_indent < 1 || new_indent < 1)
err_exit("Reindent: pass two numbers, both > 0", "");
while (gets(buf)) /* Loop for each input line. */
{
/* Count leading spaces. */
for (indent = 0; buf[indent] == ' '; ++indent)
;
new_spc = indent * new_indent / old_indent;
while (new_spc--) /* Print new leading spaces. */
putchar(' ');
puts(&buf[indent]); /* Print rest of line after spaces. */
}
}